package com.gitee.luosl.cola.match.pattern;

import com.gitee.luosl.cola.util.RegexUtil;

import java.util.List;

/**
 * Created by luosl on 2021/03/01/11:20
 */
public class RegexPattern {

    private final java.util.regex.Pattern pattern;

    public RegexPattern(java.util.regex.Pattern pattern) {
        this.pattern = pattern;
    }

    public Pattern1<String, String> apply(Pattern<String, String> p1) {
        return Pattern1.of(
                String.class,
                ignore -> true,
                Pa.pList(p1),
                str -> RegexUtil.extractGroups(pattern, str)
        );
    }

    public Pattern2<String, String, String> apply(Pattern<String, String> p1, Pattern<String, String> p2) {
        return Pattern2.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }

    public Pattern3<String, String, String, String> apply(Pattern<String, String> p1, Pattern<String, String> p2, Pattern<String, String> p3){
        return Pattern3.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2, p3),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }

    public Pattern4<String, String, String, String, String> apply(Pattern<String, String> p1, Pattern<String, String> p2, Pattern<String, String> p3, Pattern<String, String> p4){
        return Pattern4.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2, p3, p4),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }


    public Pattern2<String, String, List<String>> apply(Pattern<String, String> p1, ListPattern<String> p2){
        return Pattern2.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }

    public Pattern3<String, String, String, List<String>> apply(Pattern<String, String> p1, Pattern<String, String> p2, ListPattern<String> p3){
        return Pattern3.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2, p3),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }

    public Pattern4<String, String, String, String, List<String>> apply(Pattern<String, String> p1, Pattern<String, String> p2, Pattern<String, String> p3, ListPattern<String> p4){
        return Pattern4.of(
                Pattern1.of(
                        String.class,
                        ignore -> true,
                        Pa.pList(p1, p2, p3, p4),
                        str -> RegexUtil.extractGroups(pattern, str)
                )
        );
    }



}
